package com.gxa.wmcrm.service.Impl;

import com.gxa.wmcrm.entity.Department;
import com.gxa.wmcrm.service.BumenService;
import com.gxa.wmcrm.util.DBUtil;

import java.sql.*;
import java.sql.Date;

public class BumenServiceImpl implements BumenService {
    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
    public int addBumen(Department bumen) {
        int count=0;
        try {
            // 调用工具类DBUtil，初始化数据库驱动，创建数据库连接
            Connection conn = DBUtil.getConn();
            String sql = "insert into department(depotid,depotName,depotSetTime,depotDescribe) values (?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setInt(1,bumen.getDepotId());
            ps.setString(2,bumen.getDepotName());
            ps.setDate(3,(Date) bumen.getDepotSetTime());
            ps.setString(4,bumen.getDepotDescribe());
            count = ps.executeUpdate();

        } catch (SQLException e) {
            e.getStackTrace();
        } finally {
            DBUtil.closeConn(conn, ps, null);
        }
        return count;
    }
    public int updateBumen(Department bumen){
        int count=0;
        try {
            // 调用工具类DBUtil，初始化数据库驱动，创建数据库连接
            Connection conn = DBUtil.getConn();
            String sql = "update department set depotDescribe = ? where depotId =?";
            ps = conn.prepareStatement(sql);
            ps.setString(1,bumen.getDepotDescribe());
            ps.setInt(2,bumen.getDepotId());
            count = ps.executeUpdate();
        } catch (SQLException e) {
            e.getStackTrace();
        } finally {
            DBUtil.closeConn(conn, ps, null);
        }
        return count;

    }
}
